package com.app.controller.importExcel;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.app.common.SystemConstant;
import com.app.mapper.*;
import com.app.model.*;
import com.app.service.*;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.SpringUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import freemarker.template.utility.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileItemFactory;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItem;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.thymeleaf.util.ListUtils;

import java.io.*;
import java.net.URL;

import java.nio.file.Files;
import java.util.*;

import static org.apache.commons.codec.digest.DigestUtils.md5Hex;

/**
 * 政治工作导入
 */
@Slf4j
@RestController
@Controller
@RequestMapping("/api/import")
public class PoliticalWorkImportController {
    @Autowired
    private PersonService personService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private PersonMapper personMapper;
    @Autowired
    private PersonFamilyMapper personFamilyMapper;
    @Autowired
    private PersonTrainMapper personTrainMapper;
    @Autowired
    private PersonResumeMapper personResumeMapper;
    @Autowired
    private EnjoyMapper enjoyMapper;
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private AdminUserMapper adminUserMapper;
    @Autowired
    private RoleMapper roleMapper;


    //人员信息花名册导入
//    @PostMapping("/importPersonList")
    public Result<Object> importPersonList(MultipartFile file) {

//        //-----------------------------------------------------------------------------------------------------------------github
//        List<String> warriorList = new ArrayList<>();//战士
//        List<String> cadrerList = new ArrayList<>();//干部
//        try (ExcelReader excelReader = EasyExcelFactory.read(file.getInputStream()).build()) {
//            // 公司信息构造器
//            ReadSheet dealerSheet = EasyExcelFactory
//                    .readSheet(0)
//                    .head(PersonModel.class)
//                    .registerReadListener(new ImportExcelListener<PersonModel>(data -> {
//                        // 处理你的业务逻辑，最好抽出一个方法单独处理逻辑
//                        log.info("干部信息数据----------------------------------------------");
//                        log.info("干部信息数据：" + JSON.toJSONString(data));
//                        log.info("干部信息数据----------------------------------------------");
//                    }, cadrerList))
//                    .headRowNumber(2)
//                    .build();
//
//            // 联系人信息构造器
//            ReadSheet contactSheet = EasyExcelFactory
//                    .readSheet(1)
//                    .head(PersonModel.class)
//                    .registerReadListener(new ImportExcelListener<PersonModel>(data -> {
//                        // 处理你的业务逻辑，最好抽出一个方法单独处理逻辑
//                        log.info("战士人信息数据------------------------------------------");
//                        log.info("战士人信息数据：" + JSON.toJSONString(data));
//                        log.info("战士人信息数据------------------------------------------");
//                    }, warriorList))
//                    .build();
//
//            // 这里注意 一定要把sheet1 sheet2 一起传进去，不然有个问题就是03版的excel 会读取多次，浪费性能
//            excelReader.read(dealerSheet, contactSheet);
//        } catch (IOException e) {
//            log.error("处理excel失败，" + e.getMessage());
//        }
//        Map<String, List<String>> result = new HashMap<>(16);
//        result.put("cadrer", cadrerList);
//        result.put("warrior", warriorList);
//        log.info("导入excel完成，返回结果如下：" + JSON.toJSONString(result));
//
//        //-----------------------------------------------------------------------------------------------------------------github


        List<String> testsList = new ArrayList<>();
        try (ExcelReader excelReader = EasyExcelFactory.read(file.getInputStream()).build()) {
            // 构造器
            // 处理 sheet0 的数据（干部）
            ReadSheet dealerSheet = EasyExcelFactory
                    .readSheet(0)
                    .head(PersonModel.class)
                    .registerReadListener(new ImportExcelListener<PersonModel>(data -> {
                        log.info("------------------------------------干部信息数据--------------------------------");
                        String s = null;
                        try {
                            s = insertPersonList(data);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        if (s != null) {
                            testsList.add(s);
                        }
                        log.info("------------------------------------干部信息数据--------------------------------");
                    }, testsList))
                    .headRowNumber(2)
                    .build();
            excelReader.read(dealerSheet);
            // 处理 sheet1 的数据（战士）
            ReadSheet sheet1 = EasyExcelFactory
                    .readSheet(1)
                    .head(PersonModel.class)
                    .registerReadListener(new ImportExcelListener<PersonModel>(data -> {
                        log.info("------------------------------------战士信息数据--------------------------------");
                        try {
                            String s = insertPersonList(data); // 可能需要不同的处理方法
                            if (s != null) {
                                testsList.add(s);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        log.info("------------------------------------战士信息数据--------------------------------");
                    }, testsList))
                    .headRowNumber(2)
                    .build();
            excelReader.read(sheet1);
        } catch (IOException e) {
            log.error("处理excel失败，" + e.getMessage());
        }
        StringBuilder stringBuilder = new StringBuilder();
        if (testsList.size() > 1) {
            for (int i = 0; i < testsList.size(); i++) {
                stringBuilder.append(testsList.get(i));
            }
            List<String> result = new ArrayList<>();
            result.add(stringBuilder.toString());
            return Result.success(result);
        }
        return Result.success("");
    }

    public String insertPersonList(List<PersonModel> personModelList) throws IOException {
        if (ListUtils.isEmpty(personModelList)) {
            return null;
        }
        List<DepartmentModel> departmentModels = departmentService.getListByPid(1);
        List<PersonModel> list = new ArrayList<>();
        List<PersonModel> updateList = new ArrayList<>();
        List<String> idsList = new ArrayList<>();
        List<Integer> updateIdsList = new ArrayList<>();
        Map<String, PersonModel> personModelMap = new HashMap<>();
        List<AdminUserModel> adminUserModelArrayList = new ArrayList<>();
        for (PersonModel personModel : personModelList) {
            personModel = assignment(departmentModels, personModel);
            String personModelIdcard = personModel.getIdcard();
            idsList.add(personModelIdcard);
            personModelMap.put(personModelIdcard, personModel);
            list.add(personModel);
//            personService.insert(personModel);

        }

//        for (PersonModel personModel : personMapper.selectBatchIds(idsList)) {//已经存在的对象   根据身份证进行判断
//            PersonModel model = assignment(departmentModels, personModel);
//            updateIdsList.add(model.getId());
//            updateList.add(model);
//        }
//        personMapper.updateBatchByIds(updateList,updateIdsList);
//        personMapper.batchInsertPerson(list);
        personService.saveBatch(personModelList);
        for (PersonModel personModel : list) {
            AdminUserModel adminUserModel = setAdmin(personModel);
            adminUserModelArrayList.add(adminUserModel);
        }
        adminUserService.saveBatch(adminUserModelArrayList);
//        adminUserMapper.insertbatch(adminUserModelArrayList);
//        personMapper.batchInsertPerson(personModelList);
        assert personModelList != null;
        return "人员信息成功导入" + personModelList.size() + "行。";
    }

    /**
     * 给对象赋值
     *
     * @param departmentModels
     * @param personModel
     */
    private PersonModel assignment(List<DepartmentModel> departmentModels, PersonModel personModel) {
        if (StrUtil.isNotBlank(personModel.getEducationText1())) {
            personModel.setEducationText(personModel.getEducationText1());
        }
        if (StrUtil.isNotBlank(personModel.getRankTime1())) {
            personModel.setRankTime(personModel.getRankTime1());
        }
        if (StrUtil.isNotBlank(personModel.getSergeantNumber1())) {
            personModel.setSergeantNumber(personModel.getSergeantNumber1());
        }
        if (StrUtil.isNotBlank(personModel.getPositionDesc1())) {
            personModel.setPositionDesc(personModel.getPositionDesc1());
        }
        if (StrUtil.isNotBlank(personModel.getBirthday1())) {
            personModel.setBirthday(personModel.getBirthday1());
        }
        personModel.setId(null);
        if (personModel.getName() == null) {
            return personModel;
        }
        for (DepartmentModel departmentModel : departmentModels) {
            if (StrUtil.isNotBlank(personModel.getActualJob()) && personModel.getActualJob().contains(departmentModel.getName())) {
                personModel.setDepartmentId(departmentModel.getId());
            }
        }
        if (personModel.getRankTitle() != null) {
            if (personModel.getRankTitle().contains("校") || personModel.getRankTitle().contains("尉")) {
                personModel.setPersonType(31);
            } else {
                personModel.setPersonType(87);
            }
        }
        return personModel;
    }

    private AdminUserModel setAdmin(PersonModel model) {
        AdminUserModel adminUserModel = new AdminUserModel();
        adminUserModel.setRoles(0);
        adminUserModel.setPersonId(model.getId());
        adminUserModel.setAccount(model.getName());
        String salt = "gz_b";
        String pwd1 = md5Hex("jsxl_123456" + salt);
        adminUserModel.setPwd(pwd1);
        adminUserModel.setRealName(model.getName());
        adminUserModel.setStatus(1);
        adminUserModel.setDepartmentId(model.getDepartmentId());
        adminUserModel.setDepartmentName(model.getDepartmentText());
        return adminUserModel;
    }


    //个人信息导入
    @PostMapping("/importPerson")
    public Result<Object> importPerson(@RequestParam(value = "file") MultipartFile file, Integer type) throws Exception {//3是花名册
        log.info("文件路径：{}", file.getOriginalFilename());
        if (type == 3) {
            Result<Object> objectResult = importPersonList(file);
            return objectResult;
        }
//        return Result.error(400, "请用花名册模版导入");
//    }
//
//    //个人信息导入
//    @PostMapping("/importPersonYuanLai")
//    public Result<Object> importPersonYuanLai(@RequestParam(value = "file") MultipartFile file, Integer type) throws Exception {//3是花名册
//
//        if (type == 3) {
//            Result<Object> objectResult = null;
////            for (int i = 0; i < fileList.size(); i++) {
////                MockMultipartFile cMultiFile = new MockMultipartFile("file", fileList.get(i).getName(), null, new FileInputStream(fileList.get(i)));
//            objectResult = importPersonList(file);
////            }
//            return objectResult;
//        }


        //type =2    个人信息导入
        StringBuilder stringBuilder = new StringBuilder();
        List<String> cadreList = new ArrayList<>();
//        for (int j = 0; j < fileList.size(); j++) {
//            MockMultipartFile multipartFile = new MockMultipartFile("file", fileList.get(j).getName(), null, new FileInputStream(fileList.get(j)));
        try (ExcelReader excelReader = EasyExcelFactory.read(file.getInputStream()).build()) {
            File fileEx = update(file);
            XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(fileEx));
            int tabIndex = 0;
            Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
            Row row = null;
            Cell cell_a0 = null;
            row = sheet.getRow(1);     //指定行
            cell_a0 = row.getCell(1);  //制定列
            cell_a0.setCellType(CellType.STRING);
            String cellValue0 = cell_a0.getStringCellValue();//姓名
            Cell cell_a1 = null;
            row = sheet.getRow(2);     //指定行
            cell_a1 = row.getCell(1);  //制定列
            cell_a1.setCellType(CellType.STRING);
            String cellValue1 = cell_a1.getStringCellValue();//民族
            Cell cell_a2 = null;
            row = sheet.getRow(3);     //指定行
            cell_a2 = row.getCell(1);  //制定列
            cell_a2.setCellType(CellType.STRING);
            String cellValue2 = cell_a2.getStringCellValue();//入党时间
            Cell cell_a3;
            row = sheet.getRow(4);     //指定行
            cell_a3 = row.getCell(1);  //制定列
            cell_a3.setCellType(CellType.STRING);
            String cellValue3 = cell_a3.getStringCellValue();//学历
            Cell cell_a4 = null;
            row = sheet.getRow(5);     //指定行
            cell_a4 = row.getCell(1);  //制定列
            cell_a4.setCellType(CellType.STRING);
            String cellValue4 = cell_a4.getStringCellValue();//人员类型
            Cell cell_a5 = null;
            row = sheet.getRow(6);     //指定行
            cell_a5 = row.getCell(1);  //制定列
            cell_a5.setCellType(CellType.STRING);
            String cellValue5 = cell_a5.getStringCellValue();//军衔等级
            Cell cell_a6 = null;
            row = sheet.getRow(7);     //指定行
            cell_a6 = row.getCell(1);  //制定列
            cell_a6.setCellType(CellType.STRING);
            String cellValue6 = cell_a6.getStringCellValue();//岗位层级    换成 联系电话
            Cell cell_a7 = null;
            row = sheet.getRow(8);     //指定行
            cell_a7 = row.getCell(1);  //制定列
            cell_a7.setCellType(CellType.STRING);
            String cellValue7 = cell_a7.getStringCellValue();//待遇级别
            Cell cell_a8 = null;
            row = sheet.getRow(9);     //指定行
            cell_a8 = row.getCell(1);  //制定列
            cell_a8.setCellType(CellType.STRING);
            String cellValue8 = cell_a8.getStringCellValue();//行政职务
            Cell cell_a9 = null;
            row = sheet.getRow(10);     //指定行
            cell_a9 = row.getCell(1);  //制定列
            cell_a9.setCellType(CellType.STRING);
            String cellValue9 = cell_a9.getStringCellValue();//详细住址
            Cell cell_a10 = null;
            row = sheet.getRow(11);     //指定行
            cell_a10 = row.getCell(1);  //制定列
            cell_a10.setCellType(CellType.STRING);
            String cellValue10 = cell_a10.getStringCellValue();//现任单位及职务
            /*-----------------------------------------------------------------------------*/
            Cell cell_a11 = null;
            row = sheet.getRow(1);     //指定行
            cell_a11 = row.getCell(3);  //制定列
            cell_a11.setCellType(CellType.STRING);
            String cellValue11 = cell_a11.getStringCellValue();//性别
            Cell cell_a12 = null;
            row = sheet.getRow(2);     //指定行
            cell_a12 = row.getCell(3);  //制定列
            cell_a12.setCellType(CellType.STRING);
            String cellValue12 = cell_a12.getStringCellValue();//籍贯
            Cell cell_a13 = null;
            row = sheet.getRow(3);     //指定行
            cell_a13 = row.getCell(3);  //制定列
            cell_a13.setCellType(CellType.STRING);
            String cellValue13 = cell_a13.getStringCellValue();//参加工作时间
            Cell cell_a14 = null;
            row = sheet.getRow(4);     //指定行
            cell_a14 = row.getCell(3);  //制定列
            cell_a14.setCellType(CellType.STRING);
            String cellValue14 = cell_a14.getStringCellValue();//所学专业
            Cell cell_a15 = null;
            row = sheet.getRow(5);     //指定行
            cell_a15 = row.getCell(3);  //制定列
            cell_a15.setCellType(CellType.STRING);
            String cellValue15 = cell_a15.getStringCellValue();//入伍时间
            Cell cell_a16 = null;
            row = sheet.getRow(6);     //指定行
            cell_a16 = row.getCell(3);  //制定列
            cell_a16.setCellType(CellType.STRING);
            String cellValue16 = cell_a16.getStringCellValue();//军衔等级时间
            Cell cell_a17 = null;
            row = sheet.getRow(7);     //指定行
            cell_a17 = row.getCell(3);  //制定列
            cell_a17.setCellType(CellType.STRING);
            String cellValue17 = cell_a17.getStringCellValue();//岗位层级时间
            Cell cell_a18 = null;
            row = sheet.getRow(8);     //指定行
            cell_a18 = row.getCell(3);  //制定列
            cell_a18.setCellType(CellType.STRING);
            String cellValue18 = cell_a18.getStringCellValue();//待遇级别时间
            Cell cell_a19 = null;
            row = sheet.getRow(9);     //指定行
            cell_a19 = row.getCell(3);  //制定列
            cell_a19.setCellType(CellType.STRING);
            String cellValue19 = cell_a19.getStringCellValue();//行政职务时间

            /*-----------------------------------------------------------------------------*/
            Cell cell_a21 = null;
            row = sheet.getRow(1);     //指定行
            cell_a21 = row.getCell(5);  //制定列
            cell_a21.setCellType(CellType.STRING);
            String cellValue21 = cell_a21.getStringCellValue();//出生日期
            Cell cell_a22 = null;
            row = sheet.getRow(2);     //指定行
            cell_a22 = row.getCell(5);  //制定列
            cell_a22.setCellType(CellType.STRING);
            String cellValue22 = cell_a22.getStringCellValue();//出生地
            Cell cell_a23 = null;
            row = sheet.getRow(3);     //指定行
            cell_a23 = row.getCell(5);  //制定列
            cell_a23.setCellType(CellType.STRING);
            String cellValue23 = cell_a23.getStringCellValue();//健康状况
            Cell cell_a24 = null;
            row = sheet.getRow(4);     //指定行
            cell_a24 = row.getCell(5);  //制定列
            cell_a24.setCellType(CellType.STRING);
            String cellValue24 = cell_a24.getStringCellValue();//毕业院校
            Cell cell_a25 = null;
            row = sheet.getRow(5);     //指定行
            cell_a25 = row.getCell(5);  //制定列
            cell_a25.setCellType(CellType.STRING);
            String cellValue25 = cell_a25.getStringCellValue();//军士/军官证号
            Cell cell_a26 = null;
            row = sheet.getRow(6);     //指定行
            cell_a26 = row.getCell(5);  //制定列
            cell_a26.setCellType(CellType.STRING);
            String cellValue26 = cell_a26.getStringCellValue();//是否特殊人才
            Cell cell_a27 = null;
            row = sheet.getRow(7);     //指定行
            cell_a26 = row.getCell(5);  //制定列
            cell_a26.setCellType(CellType.STRING);
            String cellValue27 = cell_a26.getStringCellValue();//联系电话
            Cell cell_a28 = null;
            row = sheet.getRow(8);     //指定行
            cell_a26 = row.getCell(5);  //制定列
            cell_a26.setCellType(CellType.STRING);
            String cellValue28 = cell_a26.getStringCellValue();//婚姻状况
            Cell cell_a29 = null;
            row = sheet.getRow(9);     //指定行
            cell_a26 = row.getCell(5);  //制定列
            cell_a26.setCellType(CellType.STRING);
            String cellValue29 = cell_a26.getStringCellValue();//身份证号
            /*-----------------------------------------------------------------------------*/
            Cell cell_a31 = null;
            row = sheet.getRow(1);     //指定行
            cell_a31 = row.getCell(6);  //制定列
            cell_a31.setCellType(CellType.STRING);
            String cellValue31 = cell_a31.getStringCellValue();//照片
            /*-----------------------------------------------------------------------------*/


            Wrapper<PersonModel> qw = new QueryWrapper<PersonModel>()
                    .eq("idcard", cellValue29)
                    .eq("name", cellValue0);
            PersonModel personModel = personMapper.selectOne(qw);
            if (personModel == null) {
                return Result.error(400, "对象基本信息不存在，不予导入详细信息");
//                personModel = new PersonModel();
            }
            if (StrUtil.isBlank(cellValue0)) {
                return Result.error(500, "姓名不能为空");
            }
            personModel.setName(cellValue0);
            if (StrUtil.isBlank(cellValue1) && StrUtil.isBlank(personModel.getNationText())) {
                cellValue1 = "汉族";
            }
            personModel.setNationText(cellValue1);

            personModel.setRdTime(cellValue2);
            if (cellValue2 != null) {
                personModel.setZzmm(28);
            } else {
                personModel.setZzmm(30);
            }
            if (StrUtil.isBlank(cellValue3) && StrUtil.isBlank(personModel.getFirstEducationText())) {
                cellValue3 = "本科";
            }
            personModel.setFirstEducationText(cellValue3);
            CategoryModel categoryModel3 = categoryService.getPersonCate(cellValue4);
            if (categoryModel3 != null) {
                personModel.setPersonType(categoryModel3.getId());
            }
            personModel.setRankTitle(cellValue5);
            if (personModel.getRankTitle() != null) {
                if (personModel.getRankTitle().contains("校") || personModel.getRankTitle().contains("尉")) {
                    personModel.setPersonType(31);
                } else {
                    personModel.setPersonType(87);
                }
            }
            personModel.setPositionLevel(cellValue6);
            personModel.setTreatmentLevel(cellValue7);
            personModel.setAdministrativePosition(cellValue8);
            personModel.setAddress(cellValue9);
            String[] split = cellValue10.split(",");
            if (split.length != 2) {
                String[] split1 = cellValue10.split("，");
                if (split1.length == 2) {
                    DepartmentModel departmentModel = departmentService.getdepByName(split1[0]);
                    if (departmentModel != null) {
                        personModel.setDepartmentId(departmentModel.getId());
                    }
                    personModel.setPositionDesc(split1[1]);
                }
            }
            if (split.length == 2) {
                DepartmentModel departmentModel = departmentService.getdepByName(split[0]);
                if (departmentModel != null) {
                    personModel.setDepartmentId(departmentModel.getId());
                }
                personModel.setPositionDesc(split[1]);
            }
            /*-----------------------------------------------------------------------------*/
            personModel.setGender(cellValue11);
            personModel.setNativePlace(cellValue12);
            personModel.setJoinWorkTime(cellValue13);
            personModel.setMajor(cellValue14);
            personModel.setRwTime(cellValue15);
            personModel.setRankTime(cellValue16);
            personModel.setPositionTime(cellValue17);
            personModel.setTreatmentTime(cellValue18);
            personModel.setAdministrativeTime(cellValue19);
            /*-----------------------------------------------------------------------------*/

            personModel.setBirthday(cellValue21);
            personModel.setBirthPlace(cellValue22);
            personModel.setIsHealth(cellValue23);
            personModel.setSchool(cellValue24);
            personModel.setSergeantNumber(cellValue25);
            personModel.setIsSpecial(cellValue26);
            personModel.setPhone(cellValue27);
            personModel.setMaritalStatusText(cellValue28);
            personModel.setIdcard(cellValue29);
            personModel.setFaceUrl(cellValue31);
            /*-----------------------------------------------------------------------------*/
            //插入人员基本信息

            if (personModel.getId() == null) {
                personService.insert(personModel);
                AdminUserModel adminUserModel = new AdminUserModel();
                adminUserModel.setRoles(0);
                adminUserModel.setPersonId(personModel.getId());
                adminUserModel.setAccount(personModel.getName());
                String salt = "gz_b";
                String pwd1 = md5Hex("jsxl_123456" + salt);
                adminUserModel.setPwd(pwd1);
                adminUserModel.setRealName(personModel.getName());
                adminUserModel.setStatus(1);
                adminUserModel.setDepartmentId(personModel.getDepartmentId());
                adminUserModel.setDepartmentName(personModel.getDepartmentText());
                adminUserService.insert(adminUserModel);
            } else {
                personMapper.updateById(personModel);
            }
            Integer personModelId = personModel.getId();

            /*-----------------------------------------------------------------------------*/
            //导入简历信息和家庭成员及社会情况信息

            List<String> soldierList = new ArrayList<>();
            List<String> trainList = new ArrayList<>();

            // 简历信息构造器
            ReadSheet dealerSheet = EasyExcelFactory
                    .readSheet(1)
                    .head(PersonResumeModel.class)
                    .registerReadListener(new ImportExcelListener<PersonResumeModel>(data -> {
                        try {
                            String s = insertResume(data, personModelId);
                            if (s != null) {
                                cadreList.add(s);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        // 处理你的业务逻辑，最好抽出一个方法单独处理逻辑
                        log.info("简历信息数据----------------------------------------------");
                        log.info("简历信息数据：" + JSON.toJSONString(data));
                        log.info("简历信息数据----------------------------------------------");
                    }, cadreList))
                    .headRowNumber(2)
                    .build();
            // 家庭成员及社会情况信息构造器
            ReadSheet contactSheet = EasyExcelFactory
                    .readSheet(2)
                    .head(PersonFamilyModel.class)
                    .registerReadListener(new ImportExcelListener<PersonFamilyModel>(data -> {
                        try {
                            String s = insertFamily(data, personModelId);
                            if (s != null) {
                                soldierList.add(0, s);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        // 处理你的业务逻辑，最好抽出一个方法单独处理逻辑
                        log.info("家庭成员及社会情况信息数据------------------------------------------");
                        log.info("家庭成员及社会情况信息数据：" + JSON.toJSONString(data));
                        log.info("家庭成员及社会情况信息数据------------------------------------------");
                    }, soldierList))
                    .headRowNumber(2)
                    .build();
            // 军事训练信息构造器
            ReadSheet trainSheet = EasyExcelFactory
                    .readSheet(3)
                    .head(PersonTrainModel.class)
                    .registerReadListener(new ImportExcelListener<PersonTrainModel>(data -> {
                        try {
                            String s = insertTrain(data, personModelId);
                            if (s != null) {
                                trainList.add(0, s);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        // 处理你的业务逻辑，最好抽出一个方法单独处理逻辑
                        log.info("军事训练信息数据------------------------------------------");
                        log.info("军事训练信息数据：" + JSON.toJSONString(data));
                        log.info("军事训练信息数据------------------------------------------");
                    }, trainList))
                    .headRowNumber(3)
                    .build();
            excelReader.read(dealerSheet, contactSheet, trainSheet);
            fileEx.delete();
            cadreList.addAll(soldierList);
            cadreList.addAll(trainList);
        } catch (IOException e) {
            log.error("处理excel失败，" + e.getMessage());
        }
        cadreList.add(0, "文档导入成功。");
//        }
        if (cadreList.size() > 1) {
            for (int i = 0; i < cadreList.size(); i++) {
                stringBuilder.append(cadreList.get(i));
            }
            List<String> result = new ArrayList<>();
            result.add(stringBuilder.toString());
            return Result.success(result);
        } else {
            return Result.success(cadreList);
        }
    }


    private File update(MultipartFile file) throws IOException {
        String path = SystemConstant.DEFAULT_UPLOAD_URL;
        //获得上传文件名
        String fileName = file.getOriginalFilename();
        int lastIndexOf = fileName.lastIndexOf(".");
        String date = getRandomString2(8);
        //获取文件的后缀名 .jpg
        String suffix = fileName.substring(lastIndexOf);
        File filePath = new File(path + File.separator + date + suffix);
        System.out.println(filePath);
        //如果文件目录不存在，创建目录
        if (!filePath.getParentFile().exists()) {
            filePath.getParentFile().mkdirs();
        }
        file.transferTo(filePath);
        return filePath;
    }

    public static String getRandomString2(int length) {
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(3);
            long result = 0;
            switch (number) {
                case 0:
                    result = Math.round(Math.random() * 25 + 65);
                    sb.append(String.valueOf((char) result));
                    break;
                case 1:
                    result = Math.round(Math.random() * 25 + 97);
                    sb.append(String.valueOf((char) result));
                    break;
                case 2:
                    sb.append(String.valueOf(new Random().nextInt(10)));
                    break;
            }
        }
        return sb.toString();
    }

    /**
     * 简历信息批量导入
     *
     * @param personResumeModelList
     * @throws IOException
     */
    public String insertResume(List<PersonResumeModel> personResumeModelList, Integer id) throws IOException {
        List<PersonResumeModel> list = new ArrayList<>();
        if (ListUtils.isEmpty(personResumeModelList)) {
            return "简历信息有误，成功导入0行。";
        }
        for (PersonResumeModel model : personResumeModelList) {
            if (model != null && model.getStartTime() != null && model.getContent() != null && model.getEndTime() != null) {
                model.setPersonId(id);
                list.add(model);
            }
        }
        personResumeMapper.batchInsertResume(list);
        assert list != null;
        return "简历信息成功导入" + list.size() + "行。";
    }

    /**
     * 家庭成员及社会情况批量导入
     *
     * @param personFamilyModelList
     * @throws IOException
     */
    public String insertFamily(List<PersonFamilyModel> personFamilyModelList, Integer id) throws IOException {
        if (personFamilyModelList != null && !personFamilyModelList.isEmpty()) {
            for (int i = 0; i < personFamilyModelList.size(); i++) {
                personFamilyModelList.get(i).setPersonId(id);
                personFamilyModelList.get(i).setCreateTime(CommonHelp.getNowTimestamp());
                CategoryModel personCate = categoryService.getPersonCate(personFamilyModelList.get(i).getZzmmText());
                CategoryModel personCate1 = categoryService.getPersonCate(personFamilyModelList.get(i).getAppellationText());
                personFamilyModelList.get(i).setZzmm(personCate.getId());
                personFamilyModelList.get(i).setAppellation(personCate1.getId());
            }
        }
        personFamilyMapper.batchInsertFamily(personFamilyModelList);
        assert personFamilyModelList != null;
        return "家庭成员及社会情况成功导入" + personFamilyModelList.size() + "行。";
    }

    /**
     * 军事训练批量导入
     *
     * @param trainModelList
     * @param id
     * @return
     * @throws IOException
     */
    public String insertTrain(List<PersonTrainModel> trainModelList, Integer id) throws IOException {
        List<TrainResultModel> trainResultList = new ArrayList<>();
        if (trainModelList != null && !trainModelList.isEmpty()) {
            for (int i = 0; i < trainModelList.size(); i++) {
                trainModelList.get(i).setPersonId(id);
                if (trainModelList.get(i).getYear() == null) {
                    trainModelList.get(i).setYear(2023);
                }
                CategoryModel personCate = categoryService.getPersonCate(trainModelList.get(i).getTrainTotal());
                if (personCate != null) {
                    trainModelList.get(i).setTrainDesc(personCate.getId());
                }
                if (trainModelList.get(i).getTheoreticalScore() != null
                        && trainModelList.get(i).getTheoreticalLevel() != null
                        && !trainModelList.get(i).getTheoreticalLevel().equals("")) {
                    TrainResultModel model = new TrainResultModel();
                    int ran = (int) (Math.random() * 999);
                    model.setId(ran);
                    model.setTrainScore(trainModelList.get(i).getTheoreticalScore());
                    model.setTrainLevelText(trainModelList.get(i).getTheoreticalLevel());
                    if (trainModelList.get(i).getTheoreticalLevel().equals("优秀")) {
                        model.setTrainLevel(103);
                    } else if (trainModelList.get(i).getTheoreticalLevel().equals("良好")) {
                        model.setTrainLevel(104);
                    } else if (trainModelList.get(i).getTheoreticalLevel().equals("及格")) {
                        model.setTrainLevel(51);
                    } else {
                        model.setTrainLevel(52);
                    }
                    model.setTrainObject(83);
                    model.setTrainObjectText("理论考核");
                    trainResultList.add(model);
                }

                if (trainModelList.get(i).getPhysicalScore() != null
                        && trainModelList.get(i).getPhysicalLevel() != null
                        && !trainModelList.get(i).getPhysicalLevel().equals("")) {
                    TrainResultModel model = new TrainResultModel();
                    int ran = (int) (Math.random() * 999);
                    model.setId(ran);
                    model.setTrainScore(trainModelList.get(i).getPhysicalScore());
                    model.setTrainLevelText(trainModelList.get(i).getPhysicalLevel());
                    if (trainModelList.get(i).getPhysicalLevel().equals("优秀")) {
                        model.setTrainLevel(103);
                    } else if (trainModelList.get(i).getPhysicalLevel().equals("良好")) {
                        model.setTrainLevel(104);
                    } else if (trainModelList.get(i).getPhysicalLevel().equals("及格")) {
                        model.setTrainLevel(51);
                    } else {
                        model.setTrainLevel(52);
                    }
                    model.setTrainObject(54);
                    model.setTrainObjectText("军事体育");
                    trainResultList.add(model);
                }

                if (trainModelList.get(i).getEducationScore() != null
                        && trainModelList.get(i).getEducationLevel() != null
                        && !trainModelList.get(i).getEducationLevel().equals("")) {
                    TrainResultModel model = new TrainResultModel();
                    int ran = (int) (Math.random() * 999);
                    model.setId(ran);
                    model.setTrainScore(trainModelList.get(i).getEducationScore());
                    model.setTrainLevelText(trainModelList.get(i).getEducationLevel());
                    if (trainModelList.get(i).getEducationLevel().equals("优秀")) {
                        model.setTrainLevel(103);
                    } else if (trainModelList.get(i).getEducationLevel().equals("良好")) {
                        model.setTrainLevel(104);
                    } else if (trainModelList.get(i).getEducationLevel().equals("及格")) {
                        model.setTrainLevel(51);
                    } else {
                        model.setTrainLevel(52);
                    }
                    model.setTrainObject(55);
                    model.setTrainObjectText("军事职业教育");
                    trainResultList.add(model);
                }

                if (trainModelList.get(i).getWeaponScore() != null
                        && trainModelList.get(i).getWeaponLevel() != null
                        && !trainModelList.get(i).getWeaponLevel().equals("")) {
                    TrainResultModel model = new TrainResultModel();
                    int ran = (int) (Math.random() * 999);
                    model.setId(ran);
                    model.setTrainScore(trainModelList.get(i).getWeaponScore());
                    model.setTrainLevelText(trainModelList.get(i).getWeaponLevel());
                    if (trainModelList.get(i).getWeaponLevel().equals("优秀")) {
                        model.setTrainLevel(103);
                    } else if (trainModelList.get(i).getWeaponLevel().equals("良好")) {
                        model.setTrainLevel(104);
                    } else if (trainModelList.get(i).getWeaponLevel().equals("及格")) {
                        model.setTrainLevel(51);
                    } else {
                        model.setTrainLevel(52);
                    }
                    model.setTrainObject(107);
                    model.setTrainObjectText("轻武器操作");
                    trainResultList.add(model);
                }

                if (trainModelList.get(i).getPostScore() != null
                        && trainModelList.get(i).getPostLevel() != null
                        && !trainModelList.get(i).getPostLevel().equals("")) {
                    TrainResultModel model = new TrainResultModel();
                    int ran = (int) (Math.random() * 999);
                    model.setId(ran);
                    model.setTrainScore(trainModelList.get(i).getPostScore());
                    model.setTrainLevelText(trainModelList.get(i).getPostLevel());
                    if (trainModelList.get(i).getPostLevel().equals("优秀")) {
                        model.setTrainLevel(103);
                    } else if (trainModelList.get(i).getPostLevel().equals("良好")) {
                        model.setTrainLevel(104);
                    } else if (trainModelList.get(i).getPostLevel().equals("及格")) {
                        model.setTrainLevel(51);
                    } else {
                        model.setTrainLevel(52);
                    }
                    model.setTrainObject(108);
                    model.setTrainObjectText("专业岗位考核");
                    trainResultList.add(model);
                }

                trainModelList.get(i).setTrainResult(JSON.toJSONString(trainResultList));
            }
        }

        personTrainMapper.batchInsertTrain(trainModelList);
        assert trainModelList != null;
        return "军事训练成功导入" + trainModelList.size() + "行。";
    }


    /*** 根据URL地址获取文件* @param path URL网络地址* @return File*/
    private static File getFileByHttpURL(String path) {
        String newUrl = path.split("[?]")[0];
        String[] suffix = newUrl.split("/");
        String fileName = suffix[suffix.length - 1];
        File file = null;
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            file = File.createTempFile("report", fileName);
            URL urlFile = new URL(newUrl);
            inputStream = urlFile.openStream();
            outputStream = new FileOutputStream(file);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != outputStream) {
                    outputStream.close();
                }
                if (null != inputStream) {
                    inputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return file;
    }

    //福利费列表导入
    @PostMapping("/importEnjoy")
    public Result<Object> importEnjoy(@RequestParam(value = "file") MultipartFile file, Integer type) throws Exception {
        if (type == 1) {//分居费
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 4; i < 9999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(8);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String name = cell_a0.getStringCellValue();//配偶姓名
                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(9);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String idCard = cell_a1.getStringCellValue();//公民身份证号
                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(10);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String marryTime = cell_a2.getStringCellValue();//结婚时间
                        Cell cell_a3;
                        row = sheet.getRow(i);     //指定行
                        cell_a3 = row.getCell(11);  //制定列
                        cell_a3.setCellType(CellType.STRING);
                        String household = cell_a3.getStringCellValue();//户籍（双军人填常驻地）
                        Cell cell_a4 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a4 = row.getCell(12);  //制定列
                        cell_a4.setCellType(CellType.STRING);
                        String department = cell_a4.getStringCellValue();//工作单位
                        Cell cell_a5 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a5 = row.getCell(13);  //制定列
                        cell_a5.setCellType(CellType.STRING);
                        String applyTime = cell_a5.getStringCellValue();//申请享受时间
                        Cell cell_a6 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a6 = row.getCell(14);  //制定列
                        cell_a6.setCellType(CellType.STRING);
                        String giveTime = cell_a6.getStringCellValue();//批准享受时间
                        Cell cell_a7 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a7 = row.getCell(1);  //制定列
                        cell_a7.setCellType(CellType.STRING);
                        String soldier = cell_a7.getStringCellValue();//军人姓名
                        Cell cell_a8 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a8 = row.getCell(4);  //制定列
                        cell_a8.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a8.getStringCellValue();//身份证
                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel enjoyFeeModel = new EnjoyFeeModel();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setName(name);
                        enjoyFeeModel.setId_card(idCard);
                        enjoyFeeModel.setMarriage_time(marryTime);
                        enjoyFeeModel.setHousehold(household);
                        enjoyFeeModel.setWork(department);
                        enjoyFeeModel.setApply_time(applyTime);
                        enjoyFeeModel.setApprove_time(giveTime);
                        List<EnjoyFeeModel> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getSeparation() != null) {
                                    List<EnjoyFeeModel> enjoyFeeModels = JSON.parseObject(enjoyModel.getSeparation(), new TypeReference<List<EnjoyFeeModel>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setSeparation(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }
                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setSeparation(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().equals("")) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }
        }

        if (type == 2) {//随军未就业
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 4; i < 999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(8);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String name = cell_a0.getStringCellValue();//配偶姓名
                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(9);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String idCard = cell_a1.getStringCellValue();//公民身份证号
                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(10);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String marryTime = cell_a2.getStringCellValue();//结婚时间
                        Cell cell_a3;
                        row = sheet.getRow(i);     //指定行
                        cell_a3 = row.getCell(11);  //制定列
                        cell_a3.setCellType(CellType.STRING);
                        String army_time = cell_a3.getStringCellValue();//随军时间
                        Cell cell_a7 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a7 = row.getCell(1);  //制定列
                        cell_a7.setCellType(CellType.STRING);
                        String soldier = cell_a7.getStringCellValue();//军人姓名
                        Cell cell_a8 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a8 = row.getCell(4);  //制定列
                        cell_a8.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a8.getStringCellValue();//身份证
                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel2 enjoyFeeModel = new EnjoyFeeModel2();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setName(name);
                        enjoyFeeModel.setId_card(idCard);
                        enjoyFeeModel.setMarriage_time(marryTime);
                        enjoyFeeModel.setArmy_time(army_time);
                        List<EnjoyFeeModel2> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getNoEmploy() != null) {
                                    List<EnjoyFeeModel2> enjoyFeeModels = JSON.parseObject(enjoyModel.getNoEmploy(), new TypeReference<List<EnjoyFeeModel2>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setNoEmploy(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                } else {
                                    enjoyModel.setNoEmploy(s);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }
                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setNoEmploy(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().isEmpty()) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }

        }
        if (type == 3) {//子女保教费
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 4; i < 999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(8);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String name = cell_a0.getStringCellValue();//子女姓名
                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(9);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String idCard = cell_a1.getStringCellValue();//公民身份证号
                        Cell cell_a9 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a9 = row.getCell(10);  //制定列
                        cell_a9.setCellType(CellType.STRING);
                        String birthDate = cell_a9.getStringCellValue();//出生年月
                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(11);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String age = cell_a2.getStringCellValue();//年龄
                        Cell cell_a10 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a10 = row.getCell(12);  //制定列
                        cell_a10.setCellType(CellType.STRING);
                        String remark = cell_a10.getStringCellValue();//年龄
                        Cell cell_a7 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a7 = row.getCell(1);  //制定列
                        cell_a7.setCellType(CellType.STRING);
                        String soldier = cell_a7.getStringCellValue();//军人姓名
                        Cell cell_a8 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a8 = row.getCell(4);  //制定列
                        cell_a8.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a8.getStringCellValue();//身份证
                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel3 enjoyFeeModel = new EnjoyFeeModel3();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setName(name);
                        enjoyFeeModel.setId_card(idCard);
                        enjoyFeeModel.setBirthDate(birthDate);
                        enjoyFeeModel.setAge(age);
                        List<EnjoyFeeModel3> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getEducationFee() != null) {
                                    List<EnjoyFeeModel3> enjoyFeeModels = JSON.parseObject(enjoyModel.getEducationFee(), new TypeReference<List<EnjoyFeeModel3>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setEducationFee(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                } else {
                                    enjoyModel.setEducationFee(s);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }
                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setEducationFee(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().equals("")) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }

        }
        if (type == 4) {//父母赡养费
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 4; i < 999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(8);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String title = cell_a0.getStringCellValue();//称谓
                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(9);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String name = cell_a1.getStringCellValue();//父母姓名
                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(10);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String idCard = cell_a2.getStringCellValue();//公民身份证号
                        Cell cell_a3;
                        row = sheet.getRow(i);     //指定行
                        cell_a3 = row.getCell(11);  //制定列
                        cell_a3.setCellType(CellType.STRING);
                        String age = cell_a3.getStringCellValue();//年龄
                        Cell cell_a7 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a7 = row.getCell(1);  //制定列
                        cell_a7.setCellType(CellType.STRING);
                        String soldier = cell_a7.getStringCellValue();//军人姓名
                        Cell cell_a8 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a8 = row.getCell(4);  //制定列
                        cell_a8.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a8.getStringCellValue();//身份证
                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel1 enjoyFeeModel = new EnjoyFeeModel1();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setName(name);
                        enjoyFeeModel.setId_card(idCard);
                        enjoyFeeModel.setTitle(title);
                        enjoyFeeModel.setAge(age);
                        List<EnjoyFeeModel1> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getProvide() != null) {
                                    List<EnjoyFeeModel1> enjoyFeeModels = JSON.parseObject(enjoyModel.getProvide(), new TypeReference<List<EnjoyFeeModel1>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setProvide(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                } else {
                                    enjoyModel.setProvide(s);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }

                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setProvide(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().isEmpty()) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }

        }
        if (type == 7) {//父母赡养补助
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 2; i < 999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(4);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String parentsName = cell_a0.getStringCellValue();//申领父母姓名

                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(5);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String gender = cell_a1.getStringCellValue();//性别

                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(6);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String nation = cell_a2.getStringCellValue();//民族

                        Cell cell_a3 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a3 = row.getCell(7);  //制定列
                        cell_a3.setCellType(CellType.STRING);
                        String idCard = cell_a3.getStringCellValue();//公民身份证

                        Cell cell_a4 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a4 = row.getCell(8);  //制定列
                        cell_a4.setCellType(CellType.STRING);
                        String workUnit = cell_a4.getStringCellValue();//工作单位

                        Cell cell_a5 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a5 = row.getCell(9);  //制定列
                        cell_a5.setCellType(CellType.STRING);
                        String registeredResidence = cell_a5.getStringCellValue();//户籍所在地

                        Cell cell_a6;
                        row = sheet.getRow(i);     //指定行
                        cell_a6 = row.getCell(10);  //制定列
                        cell_a6.setCellType(CellType.STRING);
                        String currentAddress = cell_a6.getStringCellValue();//现住址

                        Cell cell_a7;
                        row = sheet.getRow(i);     //指定行
                        cell_a7 = row.getCell(11);  //制定列
                        cell_a7.setCellType(CellType.STRING);
                        String startingTimeOfApplication = cell_a7.getStringCellValue();//申领起起始时间

                        Cell cell_a8;
                        row = sheet.getRow(i);     //指定行
                        cell_a8 = row.getCell(12);  //制定列
                        cell_a8.setCellType(CellType.STRING);
                        String stopSendingTime = cell_a8.getStringCellValue();//停发时间

                        Cell cell_a9;
                        row = sheet.getRow(i);     //指定行
                        cell_a9 = row.getCell(13);  //制定列
                        cell_a9.setCellType(CellType.STRING);
                        String contactPhoneNumber = cell_a9.getStringCellValue();//联系电话

                        Cell cell_a10;
                        row = sheet.getRow(i);     //指定行
                        cell_a10 = row.getCell(14);  //制定列
                        cell_a10.setCellType(CellType.STRING);
                        String remarks = cell_a10.getStringCellValue();//备注
                        /*
                          获取判定人员字段
                         */
                        Cell cell_a11 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a11 = row.getCell(1);  //制定列
                        cell_a11.setCellType(CellType.STRING);
                        String soldier = cell_a11.getStringCellValue();//军人姓名

                        Cell cell_a12 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a12 = row.getCell(3);  //制定列
                        cell_a12.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a12.getStringCellValue();//身份证

                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel4 enjoyFeeModel = new EnjoyFeeModel4();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setParentsName(parentsName);
                        enjoyFeeModel.setGender(gender);
                        enjoyFeeModel.setNation(nation);
                        enjoyFeeModel.setIdCard(idCard);
                        enjoyFeeModel.setWorkUnit(workUnit);
                        enjoyFeeModel.setRegisteredResidence(registeredResidence);
                        enjoyFeeModel.setCurrentAddress(currentAddress);
                        enjoyFeeModel.setStartingTimeOfApplication(startingTimeOfApplication);
                        enjoyFeeModel.setStopSendingTime(stopSendingTime);
                        enjoyFeeModel.setContactPhoneNumber(contactPhoneNumber);
                        enjoyFeeModel.setRemarks(remarks);
                        List<EnjoyFeeModel4> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getSupportAllowance() != null) {
                                    List<EnjoyFeeModel4> enjoyFeeModels = JSON.parseObject(enjoyModel.getSupportAllowance(), new TypeReference<List<EnjoyFeeModel4>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setSupportAllowance(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                } else {
                                    enjoyModel.setSupportAllowance(s);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }

                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setSupportAllowance(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().isEmpty()) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }
        }
        if (type == 5) {//未随军无工作配偶生活补贴
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 2; i < 999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(4);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String spouseName = cell_a0.getStringCellValue();//配偶姓名

                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(5);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String registeredResidence = cell_a1.getStringCellValue();//户籍

                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(6);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String citizenIdNumber2 = cell_a2.getStringCellValue();//公民id号码2

                        Cell cell_a3 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a3 = row.getCell(7);  //制定列
                        cell_a3.setCellType(CellType.STRING);
                        String citizenIdNumber3 = cell_a3.getStringCellValue();//公民身份证号码3

                        Cell cell_a4 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a4 = row.getCell(8);  //制定列
                        cell_a4.setCellType(CellType.STRING);
                        String marriageDate = cell_a4.getStringCellValue();//结婚日期

                        Cell cell_a5 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a5 = row.getCell(9);  //制定列
                        cell_a5.setCellType(CellType.STRING);
                        String unemploymentTime = cell_a5.getStringCellValue();//失业时间

                        Cell cell_a6;
                        row = sheet.getRow(i);     //指定行
                        cell_a6 = row.getCell(10);  //制定列
                        cell_a6.setCellType(CellType.STRING);
                        String contactTime = cell_a6.getStringCellValue();//接触时间

                        Cell cell_a7;
                        row = sheet.getRow(i);     //指定行
                        cell_a7 = row.getCell(11);  //制定列
                        cell_a7.setCellType(CellType.STRING);
                        String remarks = cell_a7.getStringCellValue();//备注

                        /*
                          获取判定人员字段
                         */
                        Cell cell_a11 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a11 = row.getCell(1);  //制定列
                        cell_a11.setCellType(CellType.STRING);
                        String soldier = cell_a11.getStringCellValue();//军人姓名

                        Cell cell_a12 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a12 = row.getCell(3);  //制定列
                        cell_a12.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a12.getStringCellValue();//身份证

                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel6 enjoyFeeModel = new EnjoyFeeModel6();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setSpouseName(spouseName);
                        enjoyFeeModel.setRegisteredResidence(registeredResidence);
                        enjoyFeeModel.setCitizenIdNumber2(citizenIdNumber2);
                        enjoyFeeModel.setCitizenIdNumber3(citizenIdNumber3);
                        enjoyFeeModel.setMarriageDate(marriageDate);
                        enjoyFeeModel.setUnemploymentTime(unemploymentTime);
                        enjoyFeeModel.setContactTime(contactTime);
                        enjoyFeeModel.setRemarks(remarks);
                        List<EnjoyFeeModel6> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getNotArmy() != null) {
                                    List<EnjoyFeeModel6> enjoyFeeModels = JSON.parseObject(enjoyModel.getNotArmy(), new TypeReference<List<EnjoyFeeModel6>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setNotArmy(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                } else {
                                    enjoyModel.setNotArmy(s);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }

                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setNotArmy(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().isEmpty()) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }
        }
        if (type == 6) {//慰问、救济
            try {
                StringBuilder sb = new StringBuilder();
                if (file != null) {
                    File fileEx = update(file);
                    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(fileEx.toPath()));
                    int tabIndex = 0;
                    Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
                    for (int i = 2; i < 999; i++) {
                        Row row = null;
                        if (sheet.getRow(i).getCell(0) == null) {
                            break;
                        }
                        log.info(sheet.getRow(i).toString());
                        Cell cell_a0 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a0 = row.getCell(4);  //制定列
                        cell_a0.setCellType(CellType.STRING);
                        String reasonsForCondolenceAndRelief = cell_a0.getStringCellValue();//慰问和救济原因

                        Cell cell_a1 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a1 = row.getCell(5);  //制定列
                        cell_a1.setCellType(CellType.STRING);
                        String distributionAmount = cell_a1.getStringCellValue();//分配金额

                        Cell cell_a2 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a2 = row.getCell(6);  //制定列
                        cell_a2.setCellType(CellType.STRING);
                        String distributionTime = cell_a2.getStringCellValue();//分发时间

                        Cell cell_a3 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a3 = row.getCell(7);  //制定列
                        cell_a3.setCellType(CellType.STRING);
                        String remarks = cell_a3.getStringCellValue();//备注

                        /*
                          获取判定人员字段
                         */
                        Cell cell_a11 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a11 = row.getCell(1);  //制定列
                        cell_a11.setCellType(CellType.STRING);
                        String soldier = cell_a11.getStringCellValue();//军人姓名

                        Cell cell_a12 = null;
                        row = sheet.getRow(i);     //指定行
                        cell_a12 = row.getCell(3);  //制定列
                        cell_a12.setCellType(CellType.STRING);
                        String soldierIdCard = cell_a12.getStringCellValue();//身份证

                        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
                        Random random = new Random();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int k = 0; k < 32; k++) {
                            int i1 = random.nextInt(CHARACTERS.length());
                            char c = CHARACTERS.charAt(i1);
                            stringBuilder.append(c);
                        }
                        EnjoyFeeModel5 enjoyFeeModel = new EnjoyFeeModel5();
                        enjoyFeeModel.setId(stringBuilder.toString());
                        enjoyFeeModel.setReasonsForCondolenceAndRelief(reasonsForCondolenceAndRelief);
                        enjoyFeeModel.setDistributionAmount(distributionAmount);
                        enjoyFeeModel.setDistributionTime(distributionTime);
                        enjoyFeeModel.setRemarks(remarks);
                        List<EnjoyFeeModel5> list = new ArrayList<>();
                        list.add(enjoyFeeModel);
                        String s = JSON.toJSONString(list);

                        QueryWrapper<PersonModel> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("name", soldier);
                        queryWrapper.eq("idcard", soldierIdCard);
                        queryWrapper.eq("status", 1);
                        PersonModel personModel = personMapper.selectOne(queryWrapper);
                        if (personModel != null) {
                            QueryWrapper<EnjoyModel> queryWrapper1 = new QueryWrapper<>();
                            queryWrapper1.eq("person_id", personModel.getId());
                            EnjoyModel enjoyModel = enjoyMapper.selectOne(queryWrapper1);
                            if (enjoyModel != null) {
                                if (enjoyModel.getComfort() != null) {
                                    List<EnjoyFeeModel5> enjoyFeeModels = JSON.parseObject(enjoyModel.getComfort(), new TypeReference<List<EnjoyFeeModel5>>() {
                                    });
                                    enjoyFeeModels.add(enjoyFeeModel);
                                    String ss = JSON.toJSONString(enjoyFeeModels);
                                    enjoyModel.setComfort(ss);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                } else {
                                    enjoyModel.setComfort(s);
                                    enjoyModel.setUpdateTime(CommonHelp.getNowTimestamp());
                                    enjoyMapper.updateById(enjoyModel);
                                }

                            } else {
                                EnjoyModel enjoyModel1 = new EnjoyModel();
                                enjoyModel1.setPersonId(personModel.getId());
                                enjoyModel1.setComfort(s);
                                enjoyModel1.setCreateTime(CommonHelp.getNowTimestamp());
                                enjoyMapper.insert(enjoyModel1);
                            }
                        } else {
                            sb.append("第").append(i + 1).append("行数据人员不存在");
                        }
                    }
                }
                List<String> result = new ArrayList<>();
                if (!sb.toString().isEmpty()) {
                    result.add("导入成功，其中" + sb);
                    return Result.success(result);
                } else {
                    result.add("导入成功");
                    return Result.success(result);
                }
            } catch (Exception e) {
                List<String> result = new ArrayList<>();
                result.add("请使用正确模板");
                return Result.success(result);
            }
        }
        return Result.success("");
    }
}
